class OtherOnlineRetailersBean {
  List<OtherOnlineData>? data;
  String? msg;
  int? status;

  OtherOnlineRetailersBean({this.data, this.msg, this.status});

  OtherOnlineRetailersBean.fromJson(Map<String, dynamic> json,{required int month}) {
    if (json['data'] != null) {
      data = <OtherOnlineData>[];
      json['data'].forEach((v) {
        data!.add(new OtherOnlineData.fromJson(v,month: month));
      });
    }
    msg = json['msg'];
    status = json['status'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.data != null) {
      data['data'] = this.data!.map((v) => v.toJson()).toList();
    }
    data['msg'] = this.msg;
    data['status'] = this.status;
    return data;
  }
}

class OtherOnlineData {
  String? cMCODE;
  String? cMNAME;
  List<int>? requiredCounts;


  OtherOnlineData(
      {this.cMCODE,
        this.cMNAME,
        this.requiredCounts,});

  OtherOnlineData.fromJson(Map<String, dynamic> json, {required int month}) {
    cMCODE = json['CM_CODE'];
    cMNAME = json['CM_NAME'];

    // 获取当前的月份，直接取当前和4个月前的数据
    month;
    // 这里需要根据月份获取对应的数据
    // COUNT1 到 COUNT12 对应 1 到 12 月份的数据
    List<int> counts = [
      json['COUNT1'],
      json['COUNT2'],
      json['COUNT3'],
      json['COUNT4'],
      json['COUNT5'],
      json['COUNT6'],
      json['COUNT7'],
      json['COUNT8'],
      json['COUNT9'],
      json['COUNT10'],
      json['COUNT11'],
      json['COUNT12'],
    ];

    // 根据当前月份获取需要的数据
    List<int> requiredCounts = [];

    // 计算所需的月份索引
    for (int i = 0; i < 5; i++) {  // 过去4个月 + 当前月
      int index = (month - 1 - i + 12) % 12; // 处理0索引和负值的情况
      requiredCounts.add(counts[index]);
    }
    // 现在 requiredCounts 中包含了所需的 9, 10, 11, 12, 1 的数据
    this.requiredCounts = requiredCounts.toList();  // 反转顺序，使其从当前月开始
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['CM_CODE'] = this.cMCODE;
    data['CM_NAME'] = this.cMNAME;
    data['requiredCounts'] = this.requiredCounts;
    return data;
  }
}
